package com.abner.design.patterns.factory.simplefactory.optimization;

import com.abner.design.patterns.factory.simplefactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * 披萨店(简单工厂模式)
 * @author abner
 */
public class OrderPizza {

	Pizza pizza = null;
	public OrderPizza() {
		do {
			pizza = PizzaFactory.getPizza(getType());
			if(null == pizza) {
				System.out.println("该披萨已卖光");
				break;
			}else {
				pizza.prepare();
				pizza.bake();
				pizza.cut();
				pizza.box();
			}
		} while (true);
	}

	/**
	 * 获取控制台输入的披萨
	 * @return
	 */
	private String getType() {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza type:");
			String str = in.readLine();
			return str;
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}

}
